package ui;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import entity.main.Task;

public class DetailsPanel2 extends JPanel {
	Task curTask;
	
	private JTextField nameTextField;
	private JTextField createdTextField;
	private JTextField deadlineTextField;
	private JTextField typeTextField;
	private JTextField categoryTextField;
	private JLabel timeCompletedLabel;
	private JLabel timeToCompleteLabel;

	/**
	 * Create the panel.
	 */
	public DetailsPanel2() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblNewLabel = new JLabel("Name");
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 0;
		gbc_lblNewLabel.gridy = 0;
		add(lblNewLabel, gbc_lblNewLabel);
		
		JLabel lblNewLabel_2 = new JLabel("Time");
		GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
		gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_2.gridx = 0;
		gbc_lblNewLabel_2.gridy = 1;
		add(lblNewLabel_2, gbc_lblNewLabel_2);
		
		JPanel timeTextField = new JPanel();
		GridBagConstraints gbc_timeTextField = new GridBagConstraints();
		gbc_timeTextField.anchor = GridBagConstraints.NORTH;
		gbc_timeTextField.insets = new Insets(0, 0, 5, 0);
		gbc_timeTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_timeTextField.gridx = 1;
		gbc_timeTextField.gridy = 1;
		add(timeTextField, gbc_timeTextField);
		
		timeCompletedLabel = new JLabel("00:00");
		timeCompletedLabel.setBackground(new Color(255, 255, 255));
		timeTextField.add(timeCompletedLabel);
		
		JLabel lblNewLabel_5 = new JLabel("of");
		timeTextField.add(lblNewLabel_5);
		
		timeToCompleteLabel = new JLabel("00:00");
		timeTextField.add(timeToCompleteLabel);
		
		JLabel lblType = new JLabel("Type");
		GridBagConstraints gbc_lblType = new GridBagConstraints();
		gbc_lblType.anchor = GridBagConstraints.EAST;
		gbc_lblType.insets = new Insets(0, 0, 5, 5);
		gbc_lblType.gridx = 0;
		gbc_lblType.gridy = 2;
		add(lblType, gbc_lblType);
		
		typeTextField = new JTextField();
		typeTextField.setEditable(false);
		GridBagConstraints gbc_typeTextField = new GridBagConstraints();
		gbc_typeTextField.insets = new Insets(0, 0, 5, 0);
		gbc_typeTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_typeTextField.gridx = 1;
		gbc_typeTextField.gridy = 2;
		add(typeTextField, gbc_typeTextField);
		typeTextField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("Category");
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 0;
		gbc_lblNewLabel_1.gridy = 3;
		add(lblNewLabel_1, gbc_lblNewLabel_1);
		
		nameTextField = new JTextField();
		nameTextField.setEditable(false);
		GridBagConstraints gbc_nameTextField = new GridBagConstraints();
		gbc_nameTextField.anchor = GridBagConstraints.NORTH;
		gbc_nameTextField.insets = new Insets(0, 0, 5, 0);
		gbc_nameTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_nameTextField.gridx = 1;
		gbc_nameTextField.gridy = 0;
		add(nameTextField, gbc_nameTextField);
		nameTextField.setColumns(10);
		
		categoryTextField = new JTextField();
		categoryTextField.setEditable(false);
		categoryTextField.setColumns(10);
		GridBagConstraints gbc_categoryTextField = new GridBagConstraints();
		gbc_categoryTextField.insets = new Insets(0, 0, 5, 0);
		gbc_categoryTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_categoryTextField.gridx = 1;
		gbc_categoryTextField.gridy = 3;
		add(categoryTextField, gbc_categoryTextField);
		
		JLabel lblCreated = new JLabel("Created");
		GridBagConstraints gbc_lblCreated = new GridBagConstraints();
		gbc_lblCreated.anchor = GridBagConstraints.EAST;
		gbc_lblCreated.insets = new Insets(0, 0, 5, 5);
		gbc_lblCreated.gridx = 0;
		gbc_lblCreated.gridy = 4;
		add(lblCreated, gbc_lblCreated);
		
		createdTextField = new JTextField();
		createdTextField.setEditable(false);
		GridBagConstraints gbc_createdTextField = new GridBagConstraints();
		gbc_createdTextField.insets = new Insets(0, 0, 5, 0);
		gbc_createdTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_createdTextField.gridx = 1;
		gbc_createdTextField.gridy = 4;
		add(createdTextField, gbc_createdTextField);
		createdTextField.setColumns(10);
		
		JLabel lblDeadline = new JLabel("Deadline");
		GridBagConstraints gbc_lblDeadline = new GridBagConstraints();
		gbc_lblDeadline.anchor = GridBagConstraints.EAST;
		gbc_lblDeadline.insets = new Insets(0, 0, 5, 5);
		gbc_lblDeadline.gridx = 0;
		gbc_lblDeadline.gridy = 5;
		add(lblDeadline, gbc_lblDeadline);
		
		deadlineTextField = new JTextField();
		deadlineTextField.setEditable(false);
		GridBagConstraints gbc_deadlineTextField = new GridBagConstraints();
		gbc_deadlineTextField.insets = new Insets(0, 0, 5, 0);
		gbc_deadlineTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_deadlineTextField.gridx = 1;
		gbc_deadlineTextField.gridy = 5;
		add(deadlineTextField, gbc_deadlineTextField);
		deadlineTextField.setColumns(10);
		
		JScrollPane scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.gridwidth = 2;
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 6;
		add(scrollPane, gbc_scrollPane);
		
		JTextPane descriptionTextBox = new JTextPane();
		descriptionTextBox.setEditable(false);
		scrollPane.setViewportView(descriptionTextBox);

	}
	
	public void setTask(Task task)
	{
		this.curTask = task;
		resetDataFromTask();
	}

	public Task getCurrentTask() {
		return curTask;
	}

	public void resetDataFromTask() {		
		nameTextField.setText(curTask.getName());
		
		createdTextField.setText(curTask.getStartDate().toString());
		
		if(curTask.getDeadline() != null)
		{
			deadlineTextField.setText(curTask.getDeadline().toString());
		}
		else
		{
			deadlineTextField.setText("N/A");			
		}
		
		if(curTask.getType() == Task.TaskType.GOAL)
		{
			typeTextField.setText("Goal");			
		}
		else if(curTask.getType() == Task.TaskType.SINK)
		{
			typeTextField.setText("Sink");			
		}
		
		categoryTextField.setText(curTask.getParentObjective().getName());
		
		timeCompletedLabel.setText(curTask.getTimeSpentOnTaskThisWeek().toString());
		timeToCompleteLabel.setText(curTask.getTimePlanned().toString());
		
		this.validate();		
	}

}
